package com.flexcloudsdk.datastore;
import java.io.Serializable;
import java.util.logging.Logger;

import com.google.appengine.api.datastore.DatastoreServiceConfig;
import com.google.appengine.api.datastore.DatastoreServiceConfig.Builder;
import com.google.appengine.api.datastore.ImplicitTransactionManagementPolicy;
import com.google.appengine.api.datastore.ReadPolicy;

@SuppressWarnings("unused")
public class CloudDatastoreServiceConfig {
	private static final Logger log = Logger.getLogger(CloudDatastoreServiceConfig.class.getName());
	private String sourceClass;
	private String sourceMethod;
	
	private DatastoreServiceConfig config;
	public DatastoreServiceConfig getConfig() {
		return config;
	}

	public void setConfig(DatastoreServiceConfig config) {
		this.config = config;
	}


	public CloudDatastoreServiceConfig() {
		log.info("CloudDatastoreServiceCOnfig has been created by BlazeeDS");
		sourceMethod = Thread.currentThread().getStackTrace()[1].getMethodName().toString();
		sourceClass = CloudDatastoreServiceConfig.class.getName();
	}

	public CloudDatastoreServiceConfig  createWithDeadline(double deadline ) {
		sourceMethod = Thread.currentThread().getStackTrace()[1].getMethodName().toString();
	 	log.info("Executing: " + sourceClass + "." + sourceMethod);
	     
		config = Builder.withDeadline(deadline); 
		return this;
	}
	
	public CloudDatastoreServiceConfig createWithDefaults() {
		sourceMethod = Thread.currentThread().getStackTrace()[1].getMethodName().toString();
	 	log.info("Executing: " + sourceClass + "." + sourceMethod);
	     
		config = Builder.withDefaults();
		return this;
	}
	
	public CloudDatastoreServiceConfig createImplicitTransactionManagementPolicy(ImplicitTransactionManagementPolicy policy) {
		sourceMethod = Thread.currentThread().getStackTrace()[1].getMethodName().toString();
		log.info("Executing: " + sourceClass + "." + sourceMethod);
		     
		config = Builder.withImplicitTransactionManagementPolicy(policy)	;
		return this;
	}
	
	public CloudDatastoreServiceConfig createWithReadPolicy(ReadPolicy readpolicy) {
		sourceMethod = Thread.currentThread().getStackTrace()[1].getMethodName().toString();
		log.info("Executing: " + sourceClass + "." + sourceMethod);
	     
		config = Builder.withReadPolicy(readpolicy);
		return this;
	}
	
	public CloudDatastoreServiceConfig deadline(double deadline) {
		sourceMethod = Thread.currentThread().getStackTrace()[1].getMethodName().toString();
		log.info("Executing: " + sourceClass + "." + sourceMethod);
	     
		config = config.deadline(deadline);
		return this;
	}
	
	public double getDeadline() {
		sourceMethod = Thread.currentThread().getStackTrace()[1].getMethodName().toString();
		log.info("Executing: " + sourceClass + "." + sourceMethod);
	     
		return config.getDeadline();
	}
	
	public ImplicitTransactionManagementPolicy getImplicitTransactionManagementPolicy() {
		sourceMethod = Thread.currentThread().getStackTrace()[1].getMethodName().toString();
		log.info("Executing: " + sourceClass + "." + sourceMethod);
	     
		return config.getImplicitTransactionManagementPolicy();
	}
	
}
